﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DigitalAnts.User
{
    public partial class LoginStatus : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        /// <summary>
        /// Auto check login status of current visitor
        /// </summary>
        public void doCheckUserLoginStatus()
        { 
            if(Session["UserID"] == null && Session["Role"].ToString().Equals("Guest"))
            {
                Response.Redirect("~/User/UserLogin.aspx");
            }
            else
            {
                Response.Redirect("~/User/UserPage.aspx");
            }
        }

        /// <summary>
        /// Get user's role
        /// </summary>
        /// <returns>Guest =1; User =2; Admin =3; SuperMod=4; Mod =5</returns>
        public int getUserRole()
        {
            int _role = 0;
            if (Session["Role"].ToString().Equals("Guest"))
            {
                _role = 1;
            }
            else if(Session["Role"].ToString().Equals("User"))
            {
                _role = 2;
            }
            else if (Session["Role"].ToString().Equals("Admin"))
            {
                _role = 3;
            }
            else if (Session["Role"].ToString().Equals("SuperMod"))
            {
                _role = 4;
            }
            else if (Session["Role"].ToString().Equals("Mod"))
            {
                _role = 5;
            }
            return _role;
        }

    }
}